home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
gnu
/
smaltalk.lha
/
smalltalk-1.1.1
/
examples
/
RandomInteger.st
< prev
next >
Wrap
Text File
|
1991-09-12
|
536b
|
32 lines
"By Andy Valencia (uunet!sequent!vandys)"
"A source of random integers"
Integer subclass: #RandomInteger
instanceVariableNames: ''
classVariableNames: 'Source'
poolDictionaries: ''
category: nil.
!
RandomInteger comment:
'My instances are random integers'
!
!RandomInteger class methodsFor: 'instance creation'!
new
^ self error: 'Must use between:and:'
!
between: low and: high
| i range |
(Source = nil) ifTrue: [ Source _ Random new ].
range _ high - low.
i _ (((Source next) * (range + 1)) + low) rounded.
^ i
!!